const sqlite3 = require('../server/node_modules/sqlite3').verbose();
const path = require('path');

// 创建数据库连接
const dbPath = path.join(__dirname, '../resources/db/db.database');
console.log('Database path:', dbPath);

const db = new sqlite3.Database(dbPath);

// 查询所有表名
db.serialize(() => {
  console.log('\n=== All Tables ===');
  db.all("SELECT name FROM sqlite_master WHERE type='table'", (err, rows) => {
    if (err) {
      console.error('Error:', err);
    } else {
      console.log('Tables:', rows.map(row => row.name));
      
      // 检查每个表的结构
      rows.forEach(row => {
        console.log(`\n=== Structure of ${row.name} ===`);
        db.get("SELECT sql FROM sqlite_master WHERE type='table' AND name=?", [row.name], (err, result) => {
          if (err) {
            console.error('Error:', err);
          } else {
            console.log(result.sql);
          }
        });
      });
    }
    
    // 延迟关闭数据库连接，确保所有查询完成
    setTimeout(() => {
      db.close();
    }, 1000);
  });
});